
global name "B5_empsept_prepare"
cap log close
log using "${pfile}/${name}.smcl", replace smcl

// Creating dummy variable for workers employed in the last week of September
foreach year in 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 {

use "${prais}/`year'/2_`year's.dta", clear

format cpf %13.0g
keep year cpf dt_hir dt_dism tipoadm remmedr

g mh = month(dt_hir)

// employed in the last week of September
keep if dt_hir<=mdy(9,30,year) & dt_dism>=mdy(9,23,year)

g empdur9 = mdy(9,30,year) - max(dt_hir,mdy(9,30,year-1))
keep year cpf empdur9 remmedr

g emp9 = 1
label var emp9 "Days worked between Oct y-1 and September y"

rename remmedr remsept

sort year cpf empdur9
by year cpf: keep if _n==_N

save emp9_`year', replace
}

clear
foreach year in 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 {
append using emp9_`year'
erase "emp9_`year'.dta"
}

compress

save B5_emp9_cpf, replace

cap log close
